﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmEngineType : BaseForm
    {
        public frmEngineType()
        {
            InitializeComponent();
            statusDataBar1.addTextChange(tblEngineTypeBindingSource);
            statusDataBar1.addTextChange(gridView1);
            statusDataBar1.AddControlPrint(gridControl1);
        }

        private void frmEngineType_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsVessel.tblEngineType' table. You can move, or remove it, as needed.
            this.tblEngineTypeTableAdapter.Fill(this.dsVessel.tblEngineType);

        }

        private void statusDataBar1_NewClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblEngineTypeBindingSource.AddNew();
        }

        private void statusDataBar1_UndoClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblEngineTypeBindingSource.CancelEdit();
            this.tblEngineTypeTableAdapter.Fill(this.dsVessel.tblEngineType);
        }

        private void statusDataBar1_UpdateClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblEngineTypeBindingSource.EndEdit();
            this.tblEngineTypeTableAdapter.Update(dsVessel.tblEngineType);
            this.tblEngineTypeTableAdapter.Fill(this.dsVessel.tblEngineType);
            alertControl1.Show(this, rm.GetString("sMessageCaption", myCultureInfo), rm.GetString("sMessageSuccess", myCultureInfo));
        }

        private void statusDataBar1_DeleteClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    this.tblEngineTypeBindingSource.RemoveCurrent();
                    this.tblEngineTypeTableAdapter.Update(dsVessel.tblEngineType);
                    this.tblEngineTypeTableAdapter.Fill(this.dsVessel.tblEngineType);
                }
                catch (SqlException ex)
                {
                    this.tblEngineTypeTableAdapter.Fill(this.dsVessel.tblEngineType);
                    if (ex.ErrorCode == -2146232060)
                    {
                        XtraMessageBox.Show(rm.GetString("sDataInUsed", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        XtraMessageBox.Show(ex.Message, rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            
        }
    }
}